from selenium.webdriver.common.by import By
from base.base import Base


class Page_Alarm(Base):


    topnav_locator = (By.XPATH,'(//li[contains(@class,"ant-menu-overflow-item")])[5]')  
    input_time_locator = (By.XPATH,'//input[@placeholder="开始日期"]')
    month_locator = (By.XPATH,'(//button[@class="ant-picker-month-btn"])[1]')
    start_month_locator = (By.XPATH,'//div[@class="ant-picker-cell-inner" and text()="6月"]')
    start_day_locator = (By.XPATH,'(//div[text()="1"])[1]')
    end_day_locator = (By.XPATH,'(//div[text()="28"])[3]')
    select_btn_locator = (By.XPATH,'//span[text()="查 询"]')
    reset_btn_locator = (By.XPATH,'//span[text()="重 置"]')
    alarm_list_locator = (By.XPATH,'//td[contains(@class,"ant-table-cell")]')
    site_input_locator = (By.XPATH,'(//input[@class="ant-select-selection-search-input"])[1]')
    device_input_locator = (By.XPATH,'(//input[@class="ant-select-selection-search-input"])[2]')
    confirm_input_locator = (By.XPATH,'(//input[@class="ant-select-selection-search-input"])[4]')
    site_locator = (By.XPATH,'(//div[@class="ant-cascader-menus"]//li)[1]')
    device_locator = (By.XPATH,'//div[@class="ant-select-item-option-content" and text()="xq测试-通用测温"]')
    close_btn_locator = (By.XPATH,'//span[text()="关 闭"]')

    def page_jump(self):
        self.click(self.topnav_locator)

    def click_time_inputbox(self):
        self.click(self.input_time_locator)

    def click_month_inputbox(self):
        self.click(self.month_locator)

    def select_start_month(self):
        self.click(self.start_month_locator)

    def select_start_day(self):
        self.click(self.start_day_locator)

    def select_end_day(self):
        self.click(self.end_day_locator)

    def click_select_btn(self):
        self.click(self.select_btn_locator)
    
    def click_reset_btn(self):
        self.click(self.reset_btn_locator)


    #id 等于 返回的列数，例如id = 1,返回设备名称
    def get_alarm_list(self,id = 0):
        values = []
        newvalues = []
        for index,elm in enumerate(self.finds(self.alarm_list_locator)):
            if index%9 not in [0,8]:
                values.append(self.get_text_elm(elm))
        if id == 0:
            return values
        else:
            for index,value in enumerate(values):
                if index%7 == id:
                    newvalues.append(value)
            return newvalues
      
    def input_site(self,sitename):
        self.input(self.site_input_locator,sitename)

    def click_first_opt(self):
        self.click(self.site_locator)

    def input_device(self,devicename):
        self.input(self.device_input_locator,devicename)

    def click_device(self):
        self.click(self.device_locator)

    def click_alarm_detail(self):
        elm = self.find((By.XPATH,'(//a[text()="查看"])[1]'))
        elm.click()
        
    
    def get_alarm_detail_list(self):
        elms = self.finds((By.XPATH,'//td[@class="ant-descriptions-item-content"]'))
        values = []
        for elm in elms:
            values.append(self.get_text_elm(elm))
        return values
    
    def click_close_btn(self):
        self.click(self.close_btn_locator)